package com.ftg.learn.springbootmq.work.controller;

import com.ftg.learn.springbootmq.work.Producer.MessageProducer;
import com.ftg.learn.springbootmq.work.entity.StudentEntity;
import com.ftg.learn.util.R;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;


/**
 * @author 布衣
 */
@RestController
public class StudentController {

    @Resource
    private MessageProducer messageProducer;

    @PostMapping("/addsutdent")
    public R<Boolean> add(@RequestBody StudentEntity stu){
        messageProducer.sendStructuredMessage(stu,"add");
        return R.ok(true);
    }

    @DeleteMapping("/delete")
    public R<Boolean> delete(@RequestParam("id") String id){
        messageProducer.sendStringMessage(id,"delete");
        return R.ok(true);
    }

    @PutMapping("/update")
    public R<Boolean> update(@RequestBody StudentEntity stu){
        messageProducer.sendStructuredMessage(stu,"update");
        return R.ok(true);
    }

}
